package org.feiye.studyday28.case5;

import java.net.*;
import java.util.Scanner;
import java.io.*;

public class TalkClient2 {

	public static void main(String[] args) {
		Socket s = null;
		try {
			s = new Socket("localhost", 6666);
			InputStream in = s.getInputStream();
			OutputStream out = s.getOutputStream();
			BufferedReader br = new BufferedReader(new InputStreamReader(in));
			PrintWriter pw = new PrintWriter(out);
			Scanner sc = new Scanner(System.in);
			while (true) {
				System.out.println("请输入：");
				String s1 = sc.next();
				pw.println(s1);
				pw.flush();
				String s2 = br.readLine();
				System.out.println("服务器回复：" + s2);
				if ("exit".equals(s1))
					break;
			}

		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (s != null)
				try {
					s.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
		}

	}

}
